z = input()
if len(z) != 4 or not z.isdigit():
    print(0)
else:
    z = int(z)
m = 0
for i in range(2, z):
    if z % i == 0:
        break
else:
    m = z
h = str(z)
for i in range(len(h)):
    for j in range(i+1, len(h)+1):
        if i == 0 and h[i] == '0':
            continue
        u = int(h[i:j])
        for k in range(2, u):
            if u % k == 0:
                break
        else:
            if u > m:
                m = u
print(m)
